#include "Dispatch.h"

Dispatch::Dispatch( void )
{
	// TODO: Initialize dispatch
}

Dispatch::Dispatch( DispatchFlag flag, std::string d )
{
	// TODO: Initialize with flag and data
}

bool Dispatch::release( int sock ) const
{
	// TODO: Use send() to send information to socket 'sock'
	// HINT: The data to send should be (char)flag + data
}

long Dispatch::receive( void )
{
	//TODO: Return unless socket is valid

	//TODO: use `recv' to get data from socket
	//TODO: populate `flag' (as first bit of data)
	//TODO: populate `data' as remainder of data

	return bytes;
}

long Dispatch::receive( int s )
{
	socket = s;

	return receive();
}

void Dispatch::setFlag( DispatchFlag f )
{
	flag = f;
}

void Dispatch::setData( std::string d )
{
	data = d;
	setDataLength();
}

const DispatchFlag Dispatch::getFlag( void ) const {
	return flag;
}

const std::string Dispatch::getData( void ) const {
	return data;
}

long Dispatch::getBytes( void ) const {
	return bytes;
}

int Dispatch::getSocket( void ) const {
	return socket;
}

long Dispatch::setBytes( void )
{
	return bytes = sizeof(flag)+data.length();
}

long Dispatch::setBytes( long b )
{
	return bytes = b;
}

long Dispatch::getDataLength( void ) const {
	return dataLength;
}

long Dispatch::setDataLength( void )
{
	return dataLength = (unsigned int) data.length();
}
